package com.java.exam;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegTests {
    public static void main(String[] args) {
        String str="北京市(海淀区)(朝阳区)(昌平区)";
        Pattern p=Pattern.compile(".*?(?=\\()");
        Matcher m=p.matcher(str);
        if(m.find()){
            System.out.println(m.group());
        }
    }
}
